using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;


[AddComponentMenu("Customize/UI/Text")]
[RequireComponent(typeof(TMP_Text))]
public class LocalizationText : MonoBehaviour
{
    [SerializeField] private string localizationKey = string.Empty;
    [SerializeField] private string localizationValue = string.Empty;

    private TMP_Text text;

    private void Awake()
    {
        text = GetComponent<TMP_Text>();
    }

    private void Start()
    {
        RefreshText();
    }

    public void ShowRefresh()
    {
        RefreshText();
    }
    private void RefreshText()
    {
        if (!string.IsNullOrEmpty(localizationKey))
        {
            if (text != null)
            {
                var str = ConfigTable.Instance.tables.TbTextContent.Get(localizationKey).TextContentDetail;
                if (localizationValue != string.Empty)
                {
                    int data = PlayerData.Instance.GetData(int.Parse(localizationValue));

                    str = str.Replace("{0}", data.ToString());
                }

                text.text = str;
            }
        }
        else
        {
            Debug.LogError("Localization key is empty.");
        }
    }
}
